package my.jwds.p453;

public class MinMoves {
    public static void main(String[] args) {
        MinMoves obj = new MinMoves();
        System.out.println(obj.minMoves(new int[]{1,2,5}));
    }

    public int minMoves(int[] nums) {
        int min = nums[0];
        int count = 0;
        for (int i = 1; i < nums.length; i++) {
            if (min > nums[i]){
                count = count + i *(min-nums[i]);
                min = nums[i];
            }else{
                count+= nums[i] - min;
            }
        }
        return count;
    }
}
